/*******************************************************************************
 Configuration Information:
 Repository: Integrity Source
 Name      : $RCSfile: AR_CD_LKAColTqCalc.c $
 Version   : $Revision: 1.7 $
 Author    : $Author: Jack Jin (JinC5) $
 Date      : $Date: 2018/09/18 19:53:59IST $
 Location  : $ProjectName: /Steering/Projects/Geely/CMA_DP/PR48756_LVS_ENG_APP_Geely_CMA_EPS_DP_SYS_HRoom_AP/30_Software/3040_Design/S2-Application/01-Development/V00-Mainline/04-Components/ActiveReturn_Ear/Source/project.pj $
********************************************************************************

   ZF Friedrichshafen AG owns the copyright in this document and associated
   documents and all rights are reserved.  These documents must
   not be used for any purpose other than that for which they
   are supplied and must not be copied in whole or in part or
   disclosed to others without prior written consent of ZF Friedrichshafen AG.
   Any copy of this drawing or document made by any method
   must also include a copy of this legend.

   (C) ZF Friedrichshafen AG 2018

*******************************************************************************/
/**************************************************************************************************\
 *** 
 *** Simulink model       : AR_CD_LKAColTqCalc_tl
 *** TargetLink subsystem : AR_CD_LKAColTqCalc_tl
 *** Codefile             : AR_CD_LKAColTqCalc.c
 ***
 *** Generated by TargetLink, the dSPACE production quality code generator
 *** Model version: 1.126
 *** Generation date: 2018-09-18 14:55:11
 ***
 *** CODE GENERATOR OPTIONS:
 *** Code generation mode                     : AUTOSAR
 *** AUTOSAR version                          : 4.2.2
 *** Compiler                                 : <unknown>
 *** Target                                   : Generic
 *** ANSI-C compatible code                   : yes
 *** Code Optimization                        : enabled
 *** Constant style                           : decimal
 *** Clean code option                        : enabled
 *** Logging mode                             : Do not log anything
 *** Code Coverage                            : disabled
 *** Generate empty conditional branches      : disabled
 *** Loop unroll threshold                    : 5
 *** Shift mode                               : automatic
 *** Handle unscaled SF expr. with TL type    : enabled
 *** Assignment of conditions                 : AllBooleanOutputs 
 *** Scope reduction only to function level   : disabled
 *** Exploit ranges if not erasable           : disabled
 *** Exploit Compute Through Overflow         : never
 *** Linker sections                          : enabled
 *** Enable Assembler                         : disabled
 *** Variable name length                     : unlimited
 *** Use global bitfields                     : disabled
 *** Stateflow: use of bitfields              : enabled
 *** State activity encoding limit            : 8
 *** Omit zero inits in restart function      : disabled
 *** Share functions between TL subsystems    : disabled
 *** Generate 64bit functions                 : disabled
 *** Inlining Threshold                       : 6
 *** Line break limit                         : 100
 *** Target optimized boolean data type       : enabled
 *** Keep saturation elements                 : disabled
 *** Extended variable sharing                : disabled
 *** Extended lifetime optimization           : enabled
 *** Style definition file                    : C:\Program Files\dSPACE TargetLink 4.2\Matlab\Tl\Con
 ***                                            fig\codegen\cconfig.xml
 *** Root style sheet                         : C:\Program Files\dSPACE TargetLink 4.2\Matlab\Tl\XML
 ***                                            \CodeGen\Stylesheets\TL_CSourceCodeSS.xsl
 ***
 *** SUBSYS                   CORRESPONDING SIMULINK SUBSYSTEM
 *** SAR_CD_091               AR_CD_LKAColTqCalc_tl
 *** SAR_CD_092               AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc
 *** SAR_CD_093               AR_CD_LKAColTqCalc_tl/DocFunction
 *** SAR_CD_094               AR_CD_LKAColTqCalc_tl/IncludeAppHeader
 *** SAR_CD_095               AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/CompareTo Zero1
 *** SAR_CD_096               AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/ZFDivA_fabs2
 *** SAR_CD_097               AR_CD_LKAColTqCalc_tl/DocFunction/EmptySubsystem
 *** 
 *** SUBSYS                   CORRESPONDING MODEL BLOCK (REFERENCED MODEL)
 *** 
 *** SF-NODE   CORRESPONDING STATEFLOW NODE                           DESCRIPTION
 *** 
 *** TargetLink version      : 4.2p2 from 27-Nov-2017
 *** Code generator version  : Build Id 4.2.0.33 from 2017-11-28 14:39:24

\**************************************************************************************************/

#ifndef AR_CD_LKACOLTQCALC_C
#define AR_CD_LKACOLTQCALC_C

/*----------------------------------------------------------------------------*\
  DEFINES (OPT)
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  INCLUDES
\*----------------------------------------------------------------------------*/

#include "Rte_ActiveReturnSwc.h"
#include "AR_CD_LKAColTqCalc_tl_lut.h"
#include "AR_CD_LKAColTqCalc.h"
#include "ActiveReturnSwc_Library.h"

/*----------------------------------------------------------------------------*\
  ENUMS
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  DEFINES
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  TYPEDEFS
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  VARIABLES
\*----------------------------------------------------------------------------*/

/******************************************************************************\
   VC_STRUCT_InitAtDef: Used for global struct variables. Initialised at definition. Creates access 
   functions (get and set). | Width: N.A.
\******************************************************************************/
struct tAR_CD_LKAColTqCalc_tag var_AR_CD_LKAColTqCalc = {
   0.F, /* EarLkaColTq */
   0.F /* EarLkaTq */
};

/* Custom code: AR_CD_LKAColTqCalc_tl/IncludeAppHeader/CC_AppHeaderInclude << declaration code >> */
#include "Rte_ActiveReturnSwc.h"
/*----------------------------------------------------------------------------*\
  PARAMETERIZED MACROS
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  FUNCTION PROTOTYPES
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  INLINE FUNCTIONS
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  FUNCTION DEFINITIONS
\*----------------------------------------------------------------------------*/

/**************************************************************************************************\
 ***  FUNCTION:
 ***      AR_CD_LKAColTqCalc
 *** 
 ***  DESCRIPTION:
 ***      
 *** 
 ***  PARAMETERS:
 ***      Type               Name                Description
 ***      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ***      Float32            OpTqOvly            
 ***      UInt8              EarLkaSpdIndex      
 ***      Float32            EarLkaSpdFraction   
 ***
 ***  RETURNS:
 ***      void
 ***
 ***  SETTINGS:
 ***
\**************************************************************************************************/
void AR_CD_LKAColTqCalc(Float32 OpTqOvly, UInt8 EarLkaSpdIndex, Float32 EarLkaSpdFraction)
{
   /* SLLocal: Default storage class for local variables | Width: 32 */
   float32 SAR_CD_092_Math_Function;
   float32 SAR_CD_092_Prelookup_f; /* MIN/MAX: 0 .. 3.402823466e+38 */
   uint32 SAR_CD_092_Prelookup_k; /* LSB: 2^0 OFF: 0 MIN/MAX: 0 .. 9 */
   float32 SAR_CD_092_Saturation1;
   Float32 SAR_CD_092_Sum3;
   Float32 SAR_CD_092_w;
   float32 SAR_CD_096_Switch;

   /* SLStaticLocalInit: Default storage class for static local variables with initvalue | Width: 32
    */
   static Float32 X_SAR_CD_092_Unit_Delay = 0.F;

   /* Switch: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/ZFDivA_fabs2/Switch
      AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/ZFDivA_fabs2/Switch: Omitted comparison with constant
      .
      # combined # Relational: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/ZFDivA_fabs2/Relational Oper
      ator */
   if (OpTqOvly < 0.F) {
      /* Switch: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/ZFDivA_fabs2/Switch
         # combined # Gain: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/ZFDivA_fabs2/Gain */
      SAR_CD_096_Switch = OpTqOvly * -1.F;
   }
   else {
      /* Switch: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/ZFDivA_fabs2/Switch */
      SAR_CD_096_Switch = OpTqOvly;
   }

   /* IndexSearch: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Prelookup */
   TabIdxS48T3222_AR_CD_09((const float32 *) Rte_CData_EAR_LKA_ASSI_TQ_BRKPT(), (uint32) 10,
    SAR_CD_096_Switch, &SAR_CD_092_Prelookup_k, &SAR_CD_092_Prelookup_f);

   /* Interpolation: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Interpolation Using Prelookup */
   var_AR_CD_LKAColTqCalc.EarLkaTq = Tab2DIntp2I1T207878_AR_CD_09((const float32 *)
    Rte_CData_EAR_LKA_COL_TQ_MAP(), 10, EarLkaSpdIndex, EarLkaSpdFraction, SAR_CD_092_Prelookup_k,
    SAR_CD_092_Prelookup_f);

   /* Saturation: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Saturation1 */
   if (var_AR_CD_LKAColTqCalc.EarLkaTq > EAR_LKA_COL_TQ_MAX) {
      SAR_CD_092_Saturation1 = EAR_LKA_COL_TQ_MAX;
   }
   else {
      if (var_AR_CD_LKAColTqCalc.EarLkaTq < EAR_LKA_COL_TQ_MIN) {
         SAR_CD_092_Saturation1 = EAR_LKA_COL_TQ_MIN;
      }
      else {
         SAR_CD_092_Saturation1 = var_AR_CD_LKAColTqCalc.EarLkaTq;
      }
   }

   /* Gain: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/w */
   SAR_CD_092_w = Rte_CData_EAR_LKA_FILT_FRQ() * 6.2831853071795862F;

   /* Sum: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Sum3
      # combined # Product: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Division: 1 divided by STC_EXEC
      UTION_PERIOD */
   SAR_CD_092_Sum3 = SAR_CD_092_w + (ONE_CONST / EAR_SAMPLE_TIME);

   /* Math: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Math Function */
   if (SAR_CD_092_Sum3 != 0.F) {
      SAR_CD_092_Math_Function = 1.F / SAR_CD_092_Sum3;
   }
   else {
      /* AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Math Function: Numerator always greater than or eq
         ual to zero. */
      SAR_CD_092_Math_Function = 3.402823466e+38F;
   }

   /* Sum: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Sum2
      # combined # Unit delay: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Unit Delay
      # combined # Product: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Product2
      # combined # Sum: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Sum4 */
   X_SAR_CD_092_Unit_Delay = X_SAR_CD_092_Unit_Delay + ((SAR_CD_092_Saturation1 -
    X_SAR_CD_092_Unit_Delay) * SAR_CD_092_w * SAR_CD_092_Math_Function);

   /* Switch: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Filter Bypass */
   if (Rte_CData_EAR_LKA_FILT_FRQ() > 0.F) {
      /* SLLocal: Default storage class for local variables | Width: 8 */
      boolean SAR_CD_095_Compare;

      /* Relational: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Compare To Zero1/Compare */
      SAR_CD_095_Compare = Rte_CData_EAR_LKA_FILT_FRQ() == 0.F;

      /* Switch: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Filter Bypass
         # combined # TargetLink outport: AR_CD_LKAColTqCalc_tl/EarLkaColTq
         # combined # Sum: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Sum1
         # combined # Product: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Product1
         # combined # Product: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Product3
         # combined # AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Data Type Conversion
         # combined # Unit delay: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Unit Delay
         # combined # Logical: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Logical Operator
         # combined # AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Data Type Conversion1 */
      var_AR_CD_LKAColTqCalc.EarLkaColTq = (X_SAR_CD_092_Unit_Delay * ((float32)
       (!(SAR_CD_095_Compare)))) + (((float32) SAR_CD_095_Compare) * SAR_CD_092_Saturation1);
   }
   else {
      /* Switch: AR_CD_LKAColTqCalc_tl/AR_CD_LKAColTqCalc/Filter Bypass
         # combined # TargetLink outport: AR_CD_LKAColTqCalc_tl/EarLkaColTq */
      var_AR_CD_LKAColTqCalc.EarLkaColTq = SAR_CD_092_Saturation1;
   }
}

/*----------------------------------------------------------------------------*\
  MODULE LOCAL FUNCTION DEFINITIONS
\*----------------------------------------------------------------------------*/
#endif /* AR_CD_LKACOLTQCALC_C */
/*----------------------------------------------------------------------------*\
  END OF FILE
\*----------------------------------------------------------------------------*/
